<template>
  <div id="cornerComment" v-if="dialogVisible">
    <div class="cornerComment-in" ref="dialogBox">
      <div class="cornerComment-in-title">
        <span v-if="userType==1">例行工作历史记录</span>
        <span v-if="userType==2">发布历史记录</span>
        <span v-if="userType==3">抄送历史记录</span>
        <span class="el-icon-circle-close close-Btn-line" @click="closePOpup"></span>
      </div>
      <div class="commentBody">
        <div class="mb-10">
          <el-select placeholder="学年" v-model="semester_id" size="small"
                     class="mr-10" style="width: 180px">
            <el-option :label="item.year" :value="item.id" v-for="(item, index) in yearList" :key="index"></el-option>
          </el-select>
          <el-button type="primary" @click="searchBtn" size="small" plain><i class="el-icon-search"></i>查询</el-button>
        </div>
        <el-table
          :data="arryList"
          border
          style="width: 100%">
          <el-table-column
            prop="id"
            label="ID"
            align="center"
            width="80">
          </el-table-column>
          <el-table-column
            prop="name"
            label="例行工作名"
            align="center">
          </el-table-column>
          <el-table-column
            label="发布人"
            width="100"
            align="center">
            <template slot-scope="scope">
              {{ scope.row.admin ? scope.row.admin.realname : '--' }}
            </template>
          </el-table-column>
          <el-table-column
            label="工作类型"
            width="100"
            align="center">
            <template slot-scope="scope">
              {{ workeType[scope.row.type] }}
            </template>
          </el-table-column>
          <el-table-column
            prop="create_time"
            label="发布时间"
            align="center"
            width="110"
            :key="5">
          </el-table-column>
          <el-table-column
            label="操作"
            align="center"
            width="160">
            <template slot-scope="scope">
              <el-button type="primary" size="small" @click="workId=scope.row.id,workeDetailVisible=true" plain
                         v-if="userType == 1 || userType == 3">工作详情
              </el-button>
              <el-button type="primary" size="small" plain
                         @click="workId=scope.row.id,detailVisible=true" v-if="userType == 2">
                复制重新发布
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-col :span="24" class="toolbar">
          <el-pagination
            background
            layout="prev, pager, next"
            :total="page.total"
            :page-size="page.pagesize"
            @current-change="handleSizeChange">
          </el-pagination>
        </el-col>
      </div>
      <div class="cornerComment-in-footer">
        <el-button @click="closePOpup" size="small">返回</el-button>
      </div>
    </div>
    <workDetail :visible.sync="workeDetailVisible" :workId="workId" :acticveWorke="userType"></workDetail>
    <addWorke :visible.sync="detailVisible" :workId="workId" addType="copy"></addWorke>
  </div>
</template>

<script>
import {pagination} from '@/utils/util.js'
import {routineIndex, routineMy} from '@/api/admin/outineWorke'
import workDetail from "./work-detail";
import addWorke from "./add-outine-worke";

export default {
  props: ['visible', 'userType'],
  components: {
    workDetail,
    addWorke
  },
  data() {
    return {
      dialogVisible: false,
      detailVisible: false,
      workId: 0,
      workeDetailVisible: false,
      arryList: [],
      // 设置table页面分页所需
      page: {
        pageindex: pagination.pageIndex,
        pagesize: pagination.pageSize,
        total: pagination.total
      },
      noteId: 0,
      noteRemark: '',
      fileId: 0,
      yearList: [],
      semester_id: '',
      workeType: {
        0: '不限',
        1: '学期',
        2: '月',
        3: '周',
        4: '日'
      },
    }
  },
  watch: {
    visible() {
      this.dialogVisible = this.visible
      if (this.visible) {
        this.dayListFn()
      } else {
        this.workId = 0
        this.semester_id = ''
        this.arryList = []
        this.page = {
          pageindex: pagination.pageIndex,
          pagesize: pagination.pageSize,
          total: pagination.total
        }
      }
    }
  },
  created() {
  },
  methods: {
    searchBtn() {
      // userType 1 例行工作，2 我的发布 3 抄送
      if (this.userType === 1) {
        this.InitFn()
      }
      if (this.userType === 2 || this.userType === 3) {
        this.myPushFn()
      }
    },
    // 初始化
    async InitFn() {
      console.log('用户信息：', this.userInfo)
      let option = {
        semester_id: this.semester_id
      }
      option.p = this.page.pageindex
      // let data = await this.$post(this.api.task.archives.index, this.editForm);
      // if (this.activeName === '1') {
      // 我的例行工作
      routineMy(option).then(res => {
        for (let item of res.list.data) {
          item.create_time = item.create_time.split(' ')[0]
        }
        this.arryList = res.list.data
        this.page.total = res.list.total
      })
      // } else {
      //   // 我的抄送 我的发布
      //   option.style = 1 // 我的发布1  总揽 2 我的抄送 3
      //   routineIndex(option).then(res => {
      //     for (let item of res.list.data) {
      //       item.create_time = item.create_time.split(' ')[0]
      //     }
      //     this.arryList = res.list.data
      //     this.page.total = res.list.total
      //   })
      // }
    },
    // 我的发布
    myPushFn() {
      let option = {
        semester_id: this.semester_id
      }
      option.p = this.page.pageindex
      option.style = this.userType === 2 ? 1 : 2 // 我的发布1  总揽 2 我的抄送 3
      routineIndex(option).then(res => {
        for (let item of res.list.data) {
          item.create_time = item.create_time.split(' ')[0]
        }
        this.arryList = res.list.data
        this.page.total = res.list.total
      })
    },
    dayListFn() {
      this.$fetch(this.api.setting.semesterIndex, {}).then((response) => {
        for (let i in response.list) {
          if (response.list[i].type === 1) {
            response.list[i].year = response.list[i].year + ' 下学期'
          } else {
            response.list[i].year = response.list[i].year + ' 上学期'
          }
        }
        this.yearList = response.list
      }).catch((err) => {
        console.log(err)
      })
    },
    handleSizeChange(val) {
      this.page.pageindex = val
      this.searchBtn()
    },
    // 关闭弹窗
    closePOpup() {
      this.$emit('update:visible', false)
    },
    getJson(option) {
      return JSON.parse(JSON.stringify(option))
    },
  },
  mounted() {
  }
}
</script>
<style scoped>
#cornerComment {
  height: 100vh;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9;
}

.cornerComment-in {
  width: 76%;
  height: 550px;
  background: #fff;
  display: flex;
  flex-direction: column;
  border-radius: 5px;
}

.cornerComment-in-title {
  height: 50px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ddd;
  font-size: 24px;
}

.cornerComment-in-title span {
  padding: 0 10px;
}

.cornerComment-in-title span:first-child {
  flex: 1;
  font-size: 16px;
}

.cornerComment-in-footer {
  height: 50px;
  border-top: 1px solid #ddd;
  display: flex;
  align-items: center;
  padding: 0 10px;
  justify-content: center;
}

.commentBody {
  padding: 10px;
  flex: 1;
  overflow-y: auto;
}

.close-Btn-line {
  cursor: pointer;
}

.hearder-search {
  display: flex;
  align-items: center;
}

.remarkBody {
  white-space: pre-wrap
}
</style>


